package agent;

import java.util.Collection;

import message.AlbumsShortInfoMsg;
import message.GetAlbumsShortInfoMsg;
import model.ShortInformationBean;

import framework.Message;
import framework.agent.AbstractAgent;


public class SearchAgent extends AbstractAgent {

	private static final String NAME = "SearchAgent";
	private static SearchAgent sole;

	public static SearchAgent getSole() {
		if (sole == null) {
			sole = new SearchAgent(NAME);
		}
		return sole;
	}

	protected SearchAgent(String agentName) {
		super(agentName);
	}

	@SuppressWarnings("unchecked")
	private <M extends Message> M sendAndReceiveMsg(Message msg) {
		return (M)sendAndWait(msg, "BalkantonService");
	}

	public Collection<ShortInformationBean> searchAlbum(String q, int limit) {
		Message request = new GetAlbumsShortInfoMsg(getAgentName(),	q, limit);
		AlbumsShortInfoMsg responce = sendAndReceiveMsg(request);
		return responce.getAlbumsShortInfo();
	}
}
